package com.service.impl;

import com.dao.TypeDao;
import com.dao.impl.TypeDaoImpl;
import com.entity.Type;
import com.service.TypeService;

import java.util.List;

public class TypeServiceImpl  implements TypeService {
    TypeDao type = new TypeDaoImpl();
    @Override
    public Type getById(long id) {
        Type byId = type.getById(id);
        return byId;
    }

    @Override
    public List<Type> getAll() {
        List<Type> all = type.getAll();
        return all;
    }

    @Override
    public int modify(int id, String name) {
        int modify = type.modify(id, name);
        return modify;
    }

    @Override
    public int add(String name) {
        int add = type.add(name);
        return add;
    }

    @Override
    public int delete(int id) {
        int typeId = type.getTypeId(id);
        if(typeId>0){
            return 0;
        }else {
            return type.delete(id);
        }
    }

    @Override
    public List<Type> getByName(String typeName) {
        List<Type> types=type.getByName(typeName);
        if (types!=null){
            return types;
        }
        return null;
    }
}
